<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2020/5/10
 * Time: 8:37
 */

namespace app\common\service;


class HostExclude
{
    /**
     * @name 列表
     * @param $params
     * @param $limit
     * @return mixed
     * @Author wx
     * @date 2019/8/15 15:08
     */
    function list($hostId, $params, $limit)
    {
        $db = db('host_exclude')->where('host_id',$hostId);

        //条件筛选
        $db = $this->condition($db, $params);

        $list = $db->order('id desc')->paginate($limit)->toArray();

        return $list;
    }

    /**
     * @name 条件查询
     * @param $db
     * @param $params
     * @return mixed
     * @Author wx
     * @date 2019/8/15 15:07
     */
    function condition($db, $params)
    {
        if (isset($params['content']) && !empty($params['content'])) {
            $db->where('content', '%'.$params['content'].'%');
        }
        if (isset($params['descirption']) && !empty($params['descirption'])) {
            $db->where('descirption', 'like', '%'.$params['descirption'].'%');
        }
        if (isset($params['type']) && is_numeric($params['type'])) {
            $db->where('type', $params['type']);
        }
        if (isset($params['auto_defense']) && is_numeric($params['auto_defense'])) {
            $db->where('auto_defense', $params['auto_defense']);
        }
        if (isset($params['illegal_modify']) && is_numeric($params['illegal_modify'])) {
            $db->where('illegal_modify', $params['illegal_modify']);
        }
        if (isset($params['create']) && is_numeric($params['create'])) {
            $db->where('create', $params['create']);
        }
        if (isset($params['modify']) && is_numeric($params['modify'])) {
            $db->where('modify', $params['modify']);
        }
        if (isset($params['del']) && is_numeric($params['del'])) {
            $db->where('del', $params['del']);
        }
        if (isset($params['status']) && is_numeric($params['status'])) {
            $db->where('status', $params['status']);
        }

        return $db;
    }

    /**
     * @name 根据条件删除
     * @param $condition
     * @return bool
     * @Author wx
     * @date 2019/8/15 15:11
     */
    function del($condition){
        if(empty($condition)){
            return false;
        }

        return db('host_exclude')->where($condition)->delete();
    }

    /**
     * @name 添加
     * @param $insertData
     * @return bool|int|string
     * @Author wx
     * @date 2019/8/15 15:13
     */
    function add($insertData)
    {
        if(empty($insertData)){
            return false;
        }

        return db('host_exclude')->insert($insertData);
    }

    /**
     * @name 修改
     * @param $insertData
     * @return bool|int|string
     * @Author wx
     * @date 2019/8/15 15:13
     */
    function modify($condition, $updateData)
    {
        if(empty($updateData))
        {
            return false;
        }


        return db('HostExclude')->where($condition)->update($updateData);
    }

    /**
     * @name: 获取详情
     * @Param:
     * @Description:
     * @Author: foo
     * @Date: 2019-08-30 15:06:29
     */
    function info ($id)
    {
        $return = db('HostExclude')->find($id);

        return $return;
    }
}